package com.jiexinyun.utils.simple;

import com.jiexinyun.constants.ConstantsC;
import com.jiexinyun.utils.CommonUtils;
import com.jiexinyun.utils.uuid.UUID;
import lombok.extern.slf4j.Slf4j;
import java.sql.Timestamp;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
public class SimpleUtils {

    /**
     * 这个地方别混了，这是获取权限树的 下面还要实现一个获取子权限的
     * @param parentId
     * @param originList
     * @return
     */
//    public static List<PermsEntity> getPermsTree(String parentId, List<PermsEntity> originList) {
//        List<PermsEntity> childs = originList.stream().filter(o -> {
//            return CommonUtils.equals(parentId,o.getParentId());
//        }).sorted((o1, o2) -> o1.getSort().compareTo(o2.getSort())).collect(Collectors.toList());
//        childs.stream().forEach( o-> {
//            List<PermsEntity> r = getPermsTree(o.getId(), originList);
//            o.setChilds(r);
//        });
//        return childs;
//    }
//
//    /**
//     * 获取出不是按钮的权限
//     */
//    public static List<PermsEntity> filterNotBtn(List<PermsEntity> perms) {
//        if(CommonUtils.isNotEmpty(perms)) {
//            perms = perms.stream().filter(o-> !ConstantsC.PERM_TYPE_BTN.equals(o.getType())).collect(Collectors.toList());
//            if(CommonUtils.isNotEmpty(perms)) {
//                perms.stream().forEach(o->{
//                    List<PermsEntity> childes = o.getChilds();
//                    childes = filterNotBtn(childes);
//                    o.setChilds(childes);
//                });
//            }
//        }
//        return perms;
//    }
//
//    //获取权限集合
//    public static void capsulePcMobilePermChilds(String parentId, List<PermsEntity> originList, List<PermsEntity> returnList) {
//
//        List<PermsEntity> childs = originList.stream().filter(o -> {
//            if(CommonUtils.equals(parentId,o.getParentId())) {
////                List<PermEntity> temp = getPcMobilePermChilds(o.getId(), originList);
//                return true;
//            }
//            return false;
//        }).collect(Collectors.toList());
//        if(!childs.isEmpty()){
//            returnList.addAll(childs);
//        }
//
//        childs.stream().forEach(o-> {
//            capsulePcMobilePermChilds(o.getId(), originList, returnList);
//        });
//    }

    public static final List<String> getListStr(String str, String separator) {
        String[] arr = str.split(separator);
        return Arrays.asList(arr).stream().map(CommonUtils::trim).collect(Collectors.toList());
    }

    public static final String camelToUnderline(String camelCase) {
        if (camelCase == null || camelCase.isEmpty()) {
            return camelCase;
        }
        return camelCase.replaceAll("([a-z])([A-Z])", "$1_$2").toLowerCase();
    }

    /**
     * 生成设备清单编号
     * @param currentTime
     * @return
     */
    public static String genManifestNo(Timestamp currentTime) {
        return "ManifestNo" + UUID.fastUUID().toString();
    }

    /**
     * 生成设备文件编号
     * @param currentTime
     * @return
     */
    public static String genDeviceFileNo(Timestamp currentTime) {
        return "common" + "DeviceFileNo" + UUID.fastUUID().toString();
    }

    /**
     * 生成仓库编号
     * @param currentTime
     * @return
     */
    public static String genWarehouseNo(Timestamp currentTime) {
        return "WarehouseNo" + UUID.fastUUID().toString();
    }

    /**
     * 生成库位编号
     * @param currentTime
     * @return
     */
    public static String genLocationNo(Timestamp currentTime) {

        return "LocationNo" + UUID.fastUUID().toString();
    }

    /**
     * 备件采购计划清单编号
     * @param currentTime
     * @return
     */
    public static String genAccessoryManifestNo(Timestamp currentTime) {

        return "AccessoryManifestNo" + UUID.fastUUID().toString();
    }

    /**
     * 备件批次号
     * @param currentTime
     * @return
     */
    public static String genAccessoryBatchNo(Timestamp currentTime) {

        return "AccessoryBatchNo" + UUID.fastUUID().toString();
    }

    /**
     * 单据日期字符串
     * @param currentTime
     * @return
     */
    public static String genManifestDateStr(Timestamp currentTime) {

        return "ManifestDateStr" + UUID.fastUUID().toString();
    }

    /**
     * 备件元数据编号
     * @param currentTime
     * @return
     */
    public static String genMetadataNo(Timestamp currentTime) {

        return "genMetadataNo" + UUID.fastUUID().toString().replaceAll("-", "");
    }

    /**
     * 备件出入库单据编号
     * @param currentTime
     * @return
     */
    public static String genStoresOrderNo(Timestamp currentTime) {

        return "StoresOrderNo" + UUID.fastUUID().toString();
    }

    /**
     * 备件出入库编制日期
     * @param currentTime
     * @return
     */
    public static String genStoresOrderDateStr(Timestamp currentTime) {

        return "StoresOrderDateStr" + UUID.fastUUID().toString();
    }

}
